//
//  BootomBtnView.m
//  quxiangtao
//
//  Created by xbmios on 2018/7/26.
//  Copyright © 2018年 shanhaijin. All rights reserved.
//

#import "BootomBtnView.h"
#import "GCBadgeImageView.h"
#import "PurchaserOrderViewController.h"
#import "BuyOrderViewController.h"
#import "ShippingAddressAddViewController.h"
#import "BuyOrderContentDetailViewController.h"

@interface BootomBtnView ()

@property (strong, nonatomic) UIView *cantPayView;
@property (strong, nonatomic) UIImageView *notpayIV;
@property (strong, nonatomic) UILabel *notpayL;
//@property (strong, nonatomic) UIImageView *notpayOrderL;
@property (strong, nonatomic) GCBadgeImageView *notpayOrderL;

@property (strong, nonatomic) UIView *immediatePayView;
@property (strong, nonatomic) UIImageView *immediatePayIV;
@property (strong, nonatomic) UILabel *immediateL;

@property (assign, nonatomic) NSInteger type;
@end

@implementation BootomBtnView

- (instancetype)initWithType:(NSInteger)type {
    
    if (self = [super init]) {
        
        self.type = type;
    
        [self addSubview:self.cantPayView];
        [self.cantPayView addSubview:self.notpayIV];
        [self.cantPayView addSubview:self.notpayL];
        [self.cantPayView addSubview:self.notpayOrderL];
        
        self.cantPayView.backgroundColor = [UIColor yellowColor];
        
        [self addSubview:self.immediatePayView];
        [self.immediatePayView addSubview:self.immediatePayIV];
        [self.immediatePayView addSubview:self.immediateL];
        
        self.immediatePayView.backgroundColor = [UIColor orangeColor];

    }

    return self;
    
}


#pragma mark -未支付订单
- (void)notPayViewClick:(UIGestureRecognizer *)recognizer {
    
    self.type ? [self notStockOrder] : [self notPayOrder];

}

#pragma mark -待进货订单点击
- (void)notStockOrder {
    
    PurchaserOrderViewController *orderVC = [[PurchaserOrderViewController  alloc] init];
    orderVC.type = 0;
    [self.parentVC.navigationController pushViewController:orderVC animated:YES];
    
}

#pragma mark -待支付订单
- (void)notPayOrder {
    
    BuyOrderViewController *orderVC = [[BuyOrderViewController alloc] init];
    [self.parentVC.navigationController pushViewController:orderVC animated:YES];
    
}

#pragma mark -立即支付
- (void)immediatepayClick:(UIGestureRecognizer *)recognizer {
    
//    self.type ? NSLog(@"立即进货") : NSLog(@"立即购买") ;
    NSString *addressname = self.contentDict[@"addressname"];
    if (addressname.length > 0) {
        
        BuyOrderContentDetailViewController *vc = [[BuyOrderContentDetailViewController alloc] init];
        vc.tradeType = 0;
        vc.dict = self.contentDict;
        [self.parentVC.navigationController pushViewController:vc animated:YES];
        
    }else {
        
        ShippingAddressAddViewController *vc = [[ShippingAddressAddViewController alloc] init];
        vc.type = 1;
        vc.title = @"添加地址";
        vc.goodsInfoDict = [NSMutableDictionary dictionaryWithDictionary:self.contentDict];
        [self.parentVC.navigationController pushViewController:vc animated:YES];
        
    }

}

- (void)layoutSubviews {
    
    [super layoutSubviews];
    
    __weak typeof(self) weakSelf = self;
    [self.cantPayView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(weakSelf.mas_left);
        make.bottom.mas_equalTo(weakSelf.mas_bottom);
        make.top.mas_equalTo(weakSelf.mas_top);
        make.width.mas_equalTo(jisuan(375));
        
    }];
    [self.notpayIV mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(weakSelf.cantPayView.mas_left);
        make.bottom.mas_equalTo(weakSelf.cantPayView.mas_bottom);
        make.top.mas_equalTo(weakSelf.cantPayView.mas_top);
        make.right.mas_equalTo(weakSelf.cantPayView.mas_right);
        
    }];
    
    [self.notpayL mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(weakSelf.cantPayView.mas_left).with.offset(jisuan(80));
        make.centerY.mas_equalTo(weakSelf.cantPayView.mas_centerY);
    }];
    
    [self.notpayOrderL mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(weakSelf.notpayL.mas_right).with.offset(jisuan(10));
        make.centerY.mas_equalTo(weakSelf.notpayL.mas_centerY);
        make.width.mas_equalTo(jisuan(30));
        make.height.mas_equalTo(jisuan(36));
    }];

    [self.immediatePayView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.mas_equalTo(weakSelf.mas_right);
        make.bottom.mas_equalTo(weakSelf.mas_bottom);
        make.top.mas_equalTo(weakSelf.mas_top);
        make.width.mas_equalTo(jisuan(375));
        
    }];
    [self.immediatePayIV mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(weakSelf.immediatePayView.mas_left);
        make.bottom.mas_equalTo(weakSelf.immediatePayView.mas_bottom);
        make.top.mas_equalTo(weakSelf.immediatePayView.mas_top);
        make.right.mas_equalTo(weakSelf.immediatePayView.mas_right);
        
    }];
    
    [self.immediateL mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.mas_equalTo(weakSelf.immediatePayView.mas_centerX);
        make.centerY.mas_equalTo(weakSelf.immediatePayView.mas_centerY);
    }];
    
}

#pragma mark -lazy
- (UIView *)cantPayView {
    
    if (!_cantPayView) {
        
        _cantPayView = [[UIView alloc] init];
        _cantPayView.backgroundColor = WhiteColor;
        _cantPayView.userInteractionEnabled = YES;
        
        UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(notPayViewClick:)];
        [_cantPayView addGestureRecognizer:recognizer];

    }
    
    return _cantPayView;
}

- (UIImageView *)notpayIV {
    
    if (!_notpayIV) {
        
        _notpayIV = [[UIImageView alloc] init];
        _notpayIV.contentMode = UIViewContentModeScaleAspectFit;
        _notpayIV.image = [UIImage imageNamed:@"goodsNotPayBG"];
        _notpayIV.userInteractionEnabled = YES;
        
    }
    
    return _notpayIV;
}

- (UILabel *)notpayL {
    
    if (!_notpayL) {
        
        _notpayL = [[UILabel alloc] init];
        _notpayL.textColor = WhiteColor;
        _notpayL.textAlignment = NSTextAlignmentCenter;
        _notpayL.font =  [UIFont fontWithName:@"Helvetica-Bold" size:jisuan(30)];
        
        _notpayL.text = self.type ? @"待进货订单" : @"未支付订单";
    }
    
    return _notpayL;
}

- (GCBadgeImageView *)notpayOrderL {
    
    if (!_notpayOrderL) {
        
        _notpayOrderL = [[GCBadgeImageView alloc] initWithFrame:CGRectMake(0, 0, jisuan(30), jisuan(36))];
        _notpayOrderL.contentMode = UIViewContentModeScaleAspectFit;
        _notpayOrderL.image = [UIImage imageNamed:@"goodsOrderBG"];

//        _notpayOrderL.badgeValue = 12;
        
    }
    
    return _notpayOrderL;
}

- (UIView *)immediatePayView {
    
    if (!_immediatePayView) {
        
        _immediatePayView = [[UIView alloc] init];
        _immediatePayView.backgroundColor = WhiteColor;
        _immediatePayView.userInteractionEnabled = YES;
        UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(immediatepayClick:)];
        [_immediatePayView addGestureRecognizer:recognizer];
    
    }
    
    return _immediatePayView;
}

- (UIImageView *)immediatePayIV {
    
    if (!_immediatePayIV) {
        
        _immediatePayIV = [[UIImageView alloc] init];
        _immediatePayIV.contentMode = UIViewContentModeScaleAspectFit;

        _immediatePayIV.userInteractionEnabled = YES;
        
        _immediatePayIV.image = self.type ? [UIImage imageNamed:@"goodsImmediatePayBG"] : [UIImage imageNamed:@"shoppingGoodImmediatePayBG"];

    }
    
    return _immediatePayIV;
}

- (UILabel *)immediateL {
    
    if (!_immediateL) {
        
        _immediateL = [[UILabel alloc] init];
        _immediateL.textColor = WhiteColor;
        _immediateL.textAlignment = NSTextAlignmentCenter;
        _immediateL.font =  [UIFont fontWithName:@"Helvetica-Bold" size:jisuan(30)];
        _immediateL.text = self.type ? @"立即进货" : @"立即购买";
    
    }
    
    return _immediateL;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
